

mysql_build_dir=`pwd`

################################################

cd jemalloc-3.6.0/
sh autogen.sh 
./configure ;make ;make install

################################################

cd $mysql_build_dir

user=mysql  
group=mysql 
mkdir -p /opt/mysql/etc
id $user >& /dev/null
if [ $? -ne 0 ]
then
   	groupadd mysql && useradd -g mysql mysql -s /sbin/nologin -d /opt/mysql
 	chown -R mysql:mysql /opt/mysql
fi

source_dir="mariadb-10.0.15"
rm -rf $source_dir

if [ ! -d "$source_dir" ]; then 
	git clone https://git.oschina.net/wr4ng1er/mariadb-10.0.15.git
else
	echo $source_dir
fi

cd $source_dir

cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DMYSQL_DATADIR=/opt/mysql/data \
-DSYSCONFDIR=/opt/mysql/etc \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" \
-DWITH_SAFEMALLOC=OFF

make && make install

echo 'export PATH=$PATH:/opt/mysql/bin' >> /etc/profile 
source /etc/profile

echo 'export PATH=$PATH:/opt/mysql/bin' >> /etc/bashrc 
source /etc/bashrc

cd $mysql_build_dir

mv /etc/my.cnf /etc/my.cnf.bak
cat etc/my.cnf  >  /opt/mysql/etc/my.cnf
cat etc/init.d/mysqld  >  /etc/init.d/mysqld
ln -s  /opt/mysql/etc/my.cnf   /etc/my.cnf

chmod 755 /etc/init.d/mysqld  
chkconfig mysqld on  
chown mysql:mysql /opt/mysql -R

mkdir -p /var/lib/mysql 
ln -s /opt/mysql/lib/mysql /usr/lib/mysql  
ln -s /opt/mysql/include/mysql /usr/include/mysql 
ln -s /tmp/mysql.sock  /var/lib/mysql/mysql.sock

sudo  /opt/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data 

sudo /etc/init.d/mysqld restart
service mysqld restart

netstat -tupln | grep mysql


